package com.qf.controller;


import com.qf.constant.SystemParameter;
import com.qf.fegin.RedisService;
import com.qf.mq.SendMessageChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/web")
public class WebController {

    @Resource
    private RedisService redisService;
    @Resource
    private SendMessageChannel sendMessageChannel;


    @PostMapping("/update")
    public String update(@RequestBody Map<String,String> apiInfoBean){

        String method = apiInfoBean.get("method");
        apiInfoBean.remove("method");
        redisService.hupdate(SystemParameter.REDISAPIPRE+":"+method,apiInfoBean);
        //通过mq告诉zuul及时更新缓存
        MessageChannel messageChannel = sendMessageChannel.messageChannel();
        messageChannel.send(new GenericMessage<String>("更新数据"));
        return "update  success";
    }

}
